<template>
	<u-upload :fileList="fileList" @afterRead="afterRead" @delete="deletePic" name="" multiple :previewFullImage="true"
		:maxCount="1"></u-upload>
</template>

<script>
	export default {
		data() {
			return {
				fileList: []
			}
		},
		methods: {
			deletePic() {
				this.fileList = []
			},
			afterRead(event) {
				console.log("event", event)
				uni.uploadFile({
					url: 'https://test.jinpai.info/test-api/file/upload', //仅为示例，非真实的接口地址
					filePath: event.file[0].url,
					name: 'file',
					formData: {
						'user': 'test'
					},
					header: {
						"Authorization": uni.getStorageSync("token")
					},
					success: (uploadFileRes) => {
						console.log("成功回调")
						const url = JSON.parse(uploadFileRes.data).data.url
						console.log(JSON.parse(uploadFileRes.data).data.url);
						this.fileList = []
						this.fileList.push({
							url: url
						})
						this.$emit("input", url)
					},
					fail: (e) => {
						console.log("e", e)
					}
				});
			}
		}
	}
</script>

<style>
</style>